/* Copyright (c) 2010 Matthew Jack 
matthew.jack+mcover@gmail.com / www.matthewjack.net

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. */

// Code Coverage Tracker class
//
// A singleton, with an emphasis on minimalism to avoid skewing profiling results etc.
// Markers register with the Tracker when they are first hit and each is added to a vector
// Note that the Tracker works with Markers, but only hands out Labels (strings) in it's API

#ifndef CODECOVERAGETRACKER_H
#define CODECOVERAGETRACKER_H

#include <vector>

// Forward declarations
class CCodeCoverageMarker;


class CCodeCoverageTracker
{
public:
  // Get the singleton instance
  static CCodeCoverageTracker &GetInstance();

  // Register a Marker that has been hit with the Tracker
  void Register( CCodeCoverageMarker * pMarker );

  // Get number of markers registered so far
  int GetMarkerCount() const;

  // Input vector is cleared, then populated with the Labels of Markers hit so far
  // Optionally, skip the first n Markers - so we can collect just those newly registered
  void GetLabels( std::vector <const char *> &labels, int nFirst = 0) const;

  // Reset state of Tracker and Markers as if no Markers had been hit
  void Reset();

protected:
  // Singleton prescription: Meyers, as described in Alexandrescu
  CCodeCoverageTracker();
  ~CCodeCoverageTracker() {};
  CCodeCoverageTracker(const CCodeCoverageTracker&);
  CCodeCoverageTracker& operator=(const CCodeCoverageTracker&);

  // Vector of all Markers hit
  std::vector <CCodeCoverageMarker*> m_registeredMarkers;
};


#endif //CODECOVERAGETRACKER_H